#!/usr/bin/env python3

import os

def isPalindromicNum(num):
    """
    判断一个数是否为回文数(11 12321 1234321)
    """

    n = num
    s = 0

    while n > 0:
        s = s * 10 + n % 10
        n //= 10

    return s == num

def palindromicNumCount(s, e):
    count = 0
    while s < e:
        if isPalindromicNum(s):
            count += 1
            #  print("%d " % s, end='')
        s += 1
    #  print()

    return count

def main():
    #  print("count = ", palindromicNumCount(1000, 6000 + 1))

    print("main pid = ", os.getpid())
    for i in range(10):
        if os.fork() == 0:
            print("child pid = ", os.getpid())
            os._exit(palindromicNumCount(1000 + i * 500, 1000 + (i + 1) * 500))

    count = 0
    for i in range(10):
        pid, status = os.wait()
        count += os.WEXITSTATUS(status)

    print("count = ", count)


if __name__ == "__main__":
    main()
